# 迭代器
"""
元组、列表、字符串、集合、字典，这些都是可迭代的对象
"""
# 定义一个元组类型
tuple1 = (1,2,3)
# 创建迭代器
tup_iter = tuple1.__iter__()
# 访问下一个迭代器内容
"""
print(tup_iter.__next__())      # 1
print(tup_iter.__next__())      # 2
print(tup_iter.__next__())      # 3
print(tup_iter.__next__())      # 报错
"""
# 迭代器有一个误区
"""
list1 = [11,22,33]
print(next(list1.__iter__()))       # 11
print(next(list1.__iter__()))       # 11
print(next(list1.__iter__()))       # 11
print(next(list1.__iter__()))       # 11
"""

# 生成器
def num():
    a = 0
    while True:
        yield a     # yield：生成器关键字。代码运行到此就会return返回的，当下次再调用这个方法的时候，会从下向上来执行的
        a +=1
"""
a = num()
print(next(a))
print(next(a))
print(next(a))
"""
"""
生成器也是迭代器的一种，但是它只能迭代一次
"""
#





















